#pragma once

#include "global_config.h"

typedef enum
{
    KEY_BTN_EVENT_CLICK,
    KEY_BTN_EVENT_LONG_PRESS,
    KEY_BTN_EVENT_DOUBLE_CLICK,
    KEY_BTN_EVENT_RELEASE,
} key_btn_event_t;

typedef enum
{
    KEY_BTN1,
    KEY_BTN2,
    KEY_BTN3,
    KEY_BTN4,
} key_btn_t;

typedef enum
{
    KEY_EVENT_LOCK = 0X01,
    KEY_EVENT_UNLOCK = 0X02,
    KEY_EVENT_OPEN_WINDOW = 0X04,
    KEY_EVENT_CLOSE_WINDOW = 0X08,
    KEY_EVENT_OPEN_BACK_DOOR = 0X10,
    KEY_EVENT_CLOSE_BACK_DOOR = 0X20,
    KEY_EVENT_FIND_CAR = 0X40,
    KEY_EVENT_ENABLE = 0X80,

    KEY_EVENT_LOCK_ID = 0,
    KEY_EVENT_UNLOCK_ID,
    KEY_EVENT_OPEN_WINDOW_ID,
    KEY_EVENT_CLOSE_WINDOW_ID,
    KEY_EVENT_OPEN_BACK_DOOR_ID,
    KEY_EVENT_CLOSE_BACK_DOOR_ID,
    KEY_EVENT_FIND_CAR_ID,
    KEY_EVENT_NUMBER,
} key_event_t;

typedef struct
{
    uint8_t btn : 2;        // key_btn_t 按钮
    uint8_t event : 2;      // key_btn_event_t 单击双击长按释放
    uint8_t press_time : 4; // 0:保持按住，其他：按下时间s
} key_event_paras_t;

typedef struct
{
    uint8_t key_always_on : 1;                       // OFF(0):钥匙不长供电,ON(1)钥匙长供电
    key_event_paras_t btn_control[KEY_EVENT_NUMBER]; // KEY_EVENT_NUMBER ID : key_event_t

} key_ee_datas_t; // 掉电存储

typedef struct
{
    uint8_t key_power : 1;       // 钥匙供电 OFF(0):已关闭,ON(1)已打开
    uint8_t lock_state : 1;      // 锁状态 OFF(0):已上锁,ON(1)已解锁
    uint8_t back_door_state : 1; // 后尾门状态 OFF(0):已关闭,ON(1)已打开
    uint8_t windows_state : 1;   // 窗状态  OFF(0):已关闭,ON(1)已打开
} key_cu_datas_t;                // 实时状态

/**
 * @brief 钥匙驱动安装
 */
void drv_key_install();
